<template>
    <el-form-item label="">
    <draw-form :FormData="Parameters.FormData" :labels="Parameters.labels" title="系统设置"
      :options="Parameters.options" @submit="handleDrawerSubmit"
      :FormDataType="Parameters.FormDataType"></draw-form>
  </el-form-item>

</template>

<script lang="js">
import {DepartmentFormConfig} from '@/data/systemData.js';

import drawForm from '@/Views/common/drawForm.vue';
import {Message} from "element-ui";
import sysLoginLog, {LoginLogFormConfig} from "@/data/sysLoginLog";
import {MenuPermissionFormConfig} from "@/data/sysMenu";
import OperLogFormConfig from "@/data/sysOperationLog";
import SysPost from "@/data/sysPost";
import RoleFormConfig from "@/data/sysRole";
import {RoleMenuRelationFormConfig} from "@/data/sysRoleMenu";
import LogConfig from "@/data/unLog";
import UserTableConfig from "@/data/sysUser";

export default {

props: {
    handleDrawerSubmit: {
        type: Function,
        default: ()=>{
        },
        required:false
    },
},
name: 'commonOrder',
data() {
  return {
    names: '', // 名称字段
    Parameters: {
      FormData: {},
      labels: {},
      options: {},
      FormDataType: []
    }
  };
},
  watch: {
    '$route.name': {
      immediate: true,
      handler(newValue) {
        // Message.success(`当前路由: ${newValue}`)
        if (newValue === 'sysdept') {
          this.loadDepartmentConfig()
        } else if (newValue === 'sysloginlog') {
           Object.keys(LoginLogFormConfig).forEach(key => {
             this.Parameters[`${key}`] = LoginLogFormConfig[key]
           })
        }else if (newValue === 'sysmenu') {
          // this.transformType(MenuPermissionFormConfig)
          Object.keys(MenuPermissionFormConfig).forEach(key => {
            this.Parameters[`${key}`] = MenuPermissionFormConfig[key]
          })
        }else if (newValue === 'sysoperlog') {
          // this.transformType(MenuPermissionFormConfig)
          Object.keys(OperLogFormConfig).forEach(key => {
            this.Parameters[`${key}`] = OperLogFormConfig[key]
          })
        }else if (newValue === 'syspost') {
          Object.keys(SysPost).forEach(key => {
            this.Parameters[`${key}`] = SysPost[key]
          })
        }else if (newValue === 'sysrole') {
          Object.keys(RoleFormConfig).forEach(key => {
            this.Parameters[`${key}`] = RoleFormConfig[key]
          })
        }else if (newValue === 'sysrolemenu') {
          Object.keys(RoleMenuRelationFormConfig).forEach(key => {
            this.Parameters[`${key}`] = RoleMenuRelationFormConfig[key]
          })
        }else if (newValue === 'sysuserrole') {
          Object.keys(RoleFormConfig).forEach(key => {
            this.Parameters[`${key}`] = RoleFormConfig[key]
          })
        }else if (newValue === 'undolog') {
          Object.keys(LogConfig).forEach(key => {
            this.Parameters[`${key}`] = LogConfig[key]
          })
        }else if (newValue === 'sysuser') {
          Object.keys(UserTableConfig).forEach(key => {
            this.Parameters[`${key}`] = UserTableConfig[key]
          })
        }
      }
    }
  },
methods: {
  transformType:(TypeSys)=>{
    alert(TypeSys.FormDataType.length)
    Object.keys(TypeSys).forEach(key => {
      this.Parameters[`${key}`] = TypeSys[key]
    })
  },
  loadDepartmentConfig() {
    this.Parameters = {
      FormData: { ...DepartmentFormConfig.FormData },
      labels: { ...DepartmentFormConfig.labels },
      options: { ...DepartmentFormConfig.options },
      FormDataType: [...DepartmentFormConfig.FormDataType]
    }
  }
},
components: {
  drawForm,
},
};
</script>

<style scoped>
.common-order {
padding: 20px;
}
</style>